<!DOCTYPE HTML>
<html lang="zh" xmlns:th="https://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('表单')"/>
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="notice-form">
                <div class="select-list">
                    <ul>
                        <li>
                        	标题：<input type="text" name="title"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.addFull()">
                <i class="fa fa-plus"></i> 新增
            </a>
            <a class="btn btn-primary btn-edit single disabled" onclick="$.operate.editFull()">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger btn-del multiple disabled" onclick="$.operate.removeAll()">
                <i class="fa fa-trash"></i> 删除
            </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" data-mobile-responsive="true"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var types = [[${@dict.getType('sys_notice_type')}]];
    var datas = [[${@dict.getType('sys_notice_status')}]];
    var prefix = ctx + "form";

    function statusTools(value, row) {
        if (value == "0") {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.noticeId + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.noticeId + '\')"></i> ';
        }
    }

    /* 停用 */
    function disable(noticeId) {
        $.modal.confirm("确认要隐藏该通知吗？", function () {
            $.operate.put("/system/notice/changeDisplay/0", {"id": noticeId});
        })
    }

    /* 启用 */
    function enable(noticeId) {
        $.modal.confirm("确认要显示该通知吗？", function () {
            $.operate.put("/system/notice/changeDisplay/1", {"id": noticeId});
        })
    }

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            detailUrl: prefix + "/detail/{id}",
            modalName: "表单",
            columns: [{
                field: 'state',
                checkbox: true
            },
                {
                    field: 'id',
                    title: '序号'
                },
                {
                    field: 'title',
                    title: '标题'
                },
                {
                    field: 'createBy',
                    title: '创建者'
                },
                {
                    field: 'createTime',
                    title: '创建时间',
                    sortable: true
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.editFull(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-trash"></i>删除</a>');
                        actions.push('<a class="btn btn-info btn-xs ' + '" href="javascript:void(0)" onclick="showAddForm(\'' + row.id + '\')"><i class="fa fa-plus"></i>上报</a> ');
                        actions.push('<a class="btn btn-info btn-xs ' + '" href="javascript:void(0)" onclick="showDataList(\'' + row.id + '\')"><i class="fa fa-search"></i>记录</a> ');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);

    });
    
    function showDataList(id){
    	$.operate.detailFull($.table._option.modalName+ "详细", prefix + "/dataList?mainid="+id);
    }
    
    function showAddForm(id){
         var options = {
             title: $.table._option.modalName + "详细",
             width: '600',
             height: '400',
             url: prefix + "/detail/"+id,
             skin: 'layui-layer-gray',
             btn: ['关闭'],
             yes: function (index, layero) {
                 layer.close(index);
             }
         };
         $.modal.openOptions(options);
    }
</script>
</body>
</html>